package com.xiyu.service.controller.admin.material;
import com.xiyu.service.vo.material.stockOut.StockOutSingleGetOutput;
import com.xiyu.service.vo.material.stockOut.StockOutUpdateStatusInput;
import com.xiyu.service.vo.material.stockOut.StockOutUpdateInput;
import com.xiyu.service.vo.material.stockOut.StockOutCreateInput;
import com.xiyu.service.vo.material.stockOut.StockOutPageQueryOutput;
import com.xiyu.service.vo.material.stockOut.StockOutPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.material.StockOutService;

@Tag(name = "出库管理")
@RestController
@RequestMapping("/material/stock-out")
@Validated
public class StockOutController {

    @Resource
    private StockOutService stockOutService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询出库单")
    @PreAuthorize("@ss.hasPermission('material:stockOut:query')")
    public CommonResult<PageResult<StockOutPageQueryOutput>> pageQuery(@Valid StockOutPageQueryInput inputVO) {
        return success(stockOutService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增出库单")
    @PreAuthorize("@ss.hasPermission('material:stockOut:create')")
    public CommonResult<Long> create(@Valid @RequestBody StockOutCreateInput inputVO) {
        return success(stockOutService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新出库单")
    @PreAuthorize("@ss.hasPermission('material:stockOut:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody StockOutUpdateInput inputVO) {
        return success(stockOutService.update(inputVO));
    }

    @PutMapping("/update-status")
    @Operation(summary = "更新出库单状态")
    public CommonResult<Boolean> updateStatus(@Valid @RequestBody StockOutUpdateStatusInput inputVO) {
        return success(stockOutService.updateStatus(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个出库单")
    @Parameter(name = "id", description = "物资出库单主键ID", example = "")
    public CommonResult<StockOutSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(stockOutService.singleGet(id));
    }

}
